﻿using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Runtime.CompilerServices;
using GameViewModel.Annotations;

namespace GameViewModel
{
    public class Person : INotifyPropertyChanged
    {
        private bool _isSelected;
        private string _name;

        public Person(string name, int id)
        {
            _name = name;
            Id = id;
        }

        public int Id { get; private set; }

        [Display(Name = "Имя")]
        public virtual string Name
        {
            get { return _name; }
            set
            {
                if (value == _name) return;
                _name = value;
                OnPropertyChanged();
            }
        }

        [Display(Name = "Выбрать")]
        public virtual bool IsSelected
        {
            get { return _isSelected; }
            set
            {
                if (value.Equals(_isSelected)) return;
                _isSelected = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }

        public override string ToString()
        {
            return Name;
        }
    }
}